package main

import (
	"bytes"
	"fmt"
)

// 编写一个非递归的comma函数，运用bytes.Buffer，而不是简单的字符串拼接

func main() {
	fmt.Println(comma("123456789"))
	fmt.Println(1 << 10)
	s := [...]int{1, 2, 3, 4, 5, 6, 7, 8, 9}
	s1 := s[2:5]
	fmt.Println("len: ", len(s1))
	fmt.Println("cap: ", cap(s1))
	s2 := []int{1, 2, 3, 4, 5}
	fmt.Println("len: ", len(s2))
	fmt.Println("cap: ", cap(s2))
	s2 = append(s2, 6)
	fmt.Println("len: ", len(s2))
	fmt.Println("cap: ", cap(s2))

}

func comma(s string) string {
	var buf bytes.Buffer
	for i := 0; i < len(s); i++ {
		buf.WriteByte(s[i])
		if (i+1)%3 == 0 {
			buf.WriteByte(',')
		}
	}
	return buf.String()
}
